<!--点赞-->
<template>
  <div @click="up" v-if="flag">
    <span class="icon-up icon-like" :class="{'icon-liked':hasUp}"></span>
    {{upsCount || 0}}
  </div>
</template>

<script>
  export default {
    name: 'upsTwoComponent',
    props: ['commentId', 'upsCount','contentId'],
    components: {},
    data () {
      return {
        /*data: {
          ups: 0
        },*/
        hasUp: false,
        flag: false,
      }
    },
    created () {
     this.loadData()
      // this.data.ups = this.upsCount
    },
    methods: {
      loadData () {
        this.flag = false
        return this.fetchService.commentGetSfdz(this.commentId).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          this.hasUp = res.data
          console.log('this.hasUpthis.hasUp=',this.hasUp);
          this.flag = true
          return res
        })
      },
      up () {
        if (this.hasUp === true) {
          return false
        }
        let params = {
          commentId: this.commentId,
          type: 1,
          contentId: this.contentId,
        }
        return this.fetchService.upsAndDowns(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          this.hasUp = true
          this.$emit("updateUpsAdd")
          return res
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .title.link-arrow.link {
    border-color:#eeeeee;
    &.active {
      border-color:#0f9ceb;
    }
  }
  .icon-liked {
    display: inline-block !important;
    background: url('../../../static/images/dangjian/home/news/icon-like-active.png') no-repeat center !important;
    width: 0.4rem !important;
    height: 0.4rem !important;
    background-size: 100% 100% !important;
    margin-right: 0.13333rem !important;
  }
</style>
